/*=============================================================================

  SONY CAM INTERFACE DEFINITION

  FILE: hw_sony_cam_err.c
  
  DESCRIPTION

	SONY CAM Module Interface Definition

  EXTERNALIZED FUNCTIONS

Copyright (c) DaeSung Engineering Inc. All rights reserved.

=============================================================================*/
/*=============================================================================

  EDIT HISTORY

  ---------  -------  -------------------------------------------------------
    when          who       what, where, why
  ---------  -------  -------------------------------------------------------
    13/10/15   jyko       Initial version
   
=============================================================================*/


/*=============================================================================
  HEADER INCLUSION
=============================================================================*/
#include "hw_sony_cam_mod.h"
#include <stdio.h>
#include <string.h>

/*=============================================================================
  LOCALIZED FUNCTION DEFINITION
=============================================================================*/
#pragma pack(1)
typedef struct
{
	int32				err_code;
	const char			*err_str;
} cam_err_list_s;
#pragma pack()
	
static cam_err_list_s		cam_err_list[] = {
	{CAM_UNKNOWN_EC, "Unknown error"},
		
	// Serial Communication Error
	{CAM_COMM_ERR_EC, "Serial port open error"},

	{CAM_HW_PROTOCOL_EC, "Hardware protocol error or not support yet"},
	{CAM_HW_COMMAND_EC, "Hardware Command error"},
	{CAM_HW_STATE_EC, "Hardware state error"},
	{CAM_HW_CMD_LEN_EC, "Hardware command length error"},
	{CAM_HW_PARAM_LEN_EC, "Hardware parameter length error"},
	{CAM_HW_PARAM_RANGE_EC, "Hardware Parameter range error"},
	{CAM_HW_TIMEOUT_EC, "Hardware Time-out error"},
	{CAM_HW_ETC_EC, "ETC Hardware error"},

	{CAM_HW_CONN_EC, "Cable connection error"},
	
	// LKM Control Error
	{CAM_TIMEOUT_EC, "System is busy."},
	{CAM_INIT_EC, "Device initialization failure"},

	{CAM_NONE_EC, "No error"}
};

/*=============================================================================
  EXTERNALIZED FUNCTION DEFINITION
=============================================================================*/
int32 cam_ERRget(mcxt dev)
{
	cam_s		*cam = CAMMOD(dev);

	if(cam == NULL)
		return	CAM_UNKNOWN_EC;

	return	cam->err;
}

charptr cam_ERRstring(int32 err_code)
{
	int32		i, err_num, err_match;

	err_num = sizeof(cam_err_list) / sizeof(cam_err_list_s);

	for(err_match=0, i=0; i<err_num; i++)
	{
		if(cam_err_list[i].err_code == err_code)
		{
			err_match = i;
			break;
		}
	}
	
	return	(char*)cam_err_list[err_match].err_str;
}

/*=============================================================================
  LOCALIZED FUNCTION DEFINTION
=============================================================================*/

void cam_err_set(cam_s *cam, int32 err)
{
	cam->err = err;
}

void cam_err_clear(cam_s *cam)
{
	cam->err = CAM_NONE_EC;
}

/*--- END OF hw_sony_cam_err.c ---*/
